<script setup>
import {onBeforeUnmount, onMounted, ref} from "vue";
import {signList} from "@/api/sign.js";
import {formatDate} from "@vueuse/shared";

const signInStatus = ref(true)
const signInList = ref([])

const thisUsername = ref(JSON.parse(localStorage.getItem('userInfo')).username)

const getSignList = async () => {
  const list = await signList(pageForm.value)
  signInList.value = list.data.records
  total.value = list.data.total
  pageSize.value = list.data.size
}

const props = defineProps({
  username: {
    type: String,
    default: '',
    required: false
  }
});

onMounted(() => {
  if (props.username !== undefined && props.username !== '' && props.username !== null) {
    pageForm.value.username = props.username;
  }
  getSignList()
})

const currentPage = ref(1);
const pageSize = ref(5);
const total = ref();

const pageForm = ref({
  page: 1,
  size: 5,
  username: thisUsername.value
})

const handleCurrentChange = (page) => {
  currentPage.value = page;
  // 在这里可以触发数据加载逻辑
  pageForm.value.page = page;
  getSignList()
};



</script>

<template>
  <div>
    <el-table :data="signInList" :border="true" style="height: 200px">
      <el-table-column prop="attendanceId" label="ID"></el-table-column>
      <el-table-column prop="checkIn" label="签到时间"></el-table-column>
      <el-table-column prop="checkOut" label="签退时间"></el-table-column>
      <el-table-column prop="status" label="状态">
        <template #default="scope">
            <span v-if="scope.row.status === 0" style="color: green">
              正常
            </span>
          <span v-else-if="scope.row.status === 1" style="color: orange">
              迟到
          </span>
          <span v-else-if="scope.row.status === 2" style="color: orange">
              早退
            </span>
          <span v-else style="color: red">
              缺勤
            </span>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 20px; text-align: center">
      <el-pagination
          :page-size="pageSize"
          :total="total"
          :current-page="currentPage"
          @current-change="handleCurrentChange"
          layout="prev, pager, next"
      />
    </div>
  </div>
</template>

<style scoped>

</style>
